package com.heima.admin.controller.v1;
import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.dtos.ResponseResult;
import com.heima.model.admin.pojos.AdChannel;
import com.sun.jndi.cosnaming.CNCtx;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "频道管理API接口",tags = "频道管理API接口",description = "管理频道相关接口")
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {
    //给前端提供接口
    @Autowired
    AdChannelService adChannelService;
    //ResponseResult 返回值类型是父类
    @ApiOperation(value = "分页查询频道列表",notes = "按照name模糊查询,分页查询,按照ord升序排序")
    @PostMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDTO dto){
        return adChannelService.findByNameAndPage(dto);
    }

    @ApiOperation(value = "频道新增")
    @PostMapping("/save")
    public ResponseResult addAdChannel(@RequestBody AdChannel adChannel){
        return adChannelService.addAdChannel(adChannel);
    }
    @ApiOperation(value = "频道编辑")
    @PostMapping("/update")
    public ResponseResult updateAdChanner(@RequestBody AdChannel adChannel){
        return  adChannelService.updateAdChanner(adChannel);
    }

   @ApiOperation("根据频道ID删除")
    @GetMapping("/del/{id}")
    public ResponseResult deleteAdChannel(@PathVariable("id") Integer id){
        return adChannelService.deleteAdChannel(id);
   }

  @ApiOperation("查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findAll() {

        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
}
